package com.example.demo.controller;

import com.example.demo.annotation.RateLimiter;
import com.example.demo.dto.ResponseResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @RateLimiter(userLimit = 5)
    @RequestMapping("/hello")
    public ResponseResult<String> hello(){
        ResponseResult<String> result=new ResponseResult<>();
        result.setCode("000000");
        result.setStatus("success");
        result.setData("hello");

        return result;
    }

    @RateLimiter()
    @RequestMapping("/hello2")
    public ResponseResult<String> hello2(){
        ResponseResult<String> result=new ResponseResult<>();
        result.setCode("000000");
        result.setStatus("success");
        result.setData("hello2");

        return result;
    }

    @ExceptionHandler
    public ResponseResult<String> handleError(Exception e){
        ResponseResult<String> result=new ResponseResult<>();
        result.setCode("111111");
        result.setStatus("error");
        result.setMessage(e.getMessage());

        return  result;
    }
}
